﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Net;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AppShare.Web
{
    public partial class SubmitData
    {
        private OperationBase currentOperation;

        /// <summary>
        /// Gets or sets the current registration or login operation.
        /// </summary>
        internal OperationBase CurrentOperation
        {
            get
            {
                return this.currentOperation;
            }
            set
            {
                if (this.currentOperation != value)
                {
                    if (this.currentOperation != null)
                    {
                        this.currentOperation.Completed -= (s, e) => this.CurrentOperationChanged();
                    }

                    this.currentOperation = value;

                    if (this.currentOperation != null)
                    {
                        this.currentOperation.Completed += (s, e) => this.CurrentOperationChanged();
                    }

                    this.CurrentOperationChanged();
                }
            }
        }


        /// <summary>
        /// Helper method for when the current operation changes.
        /// Used to raise appropriate property change notifications.
        /// </summary>
        private void CurrentOperationChanged()
        {
            this.RaisePropertyChanged("IsWorking");
        }

        /// <summary>
        /// Gets a value indicating whether the user is presently being registered or logged in.
        /// </summary>
        [Display(AutoGenerateField = false)]
        public bool IsWorking
        {
            get
            {
                return this.CurrentOperation != null && !this.CurrentOperation.IsComplete;
            }
        }

        [Display(AutoGenerateField = false)]
        public FileInfo File { get; set; }

        public string GetMuleLink()
        {
            return string.Format("ed2k://|file|{0}|{1}|{2}|/", Encode(File.Name), File.Length, eMuleHash);
        }
        private string Encode(string p)
        {
            return HttpUtility.UrlEncode(p).ToUpper();
        }
    }

    public partial class ProductData
    {
        private IEnumerable<FamilyData> families;
        public IEnumerable<FamilyData> Families
        {
            get { return families; }
            set
            {
                families = value;
                RaisePropertyChanged("Families");
            }
        }
    }
}
